<template>
    <transition name="showFn">
        <div class="toast">
            <i :class="getClass"></i>
            <span>{{ toastMsg }}</span>
        </div>
    </transition>
</template>
 
 <script>
import { mapState } from "vuex";
export default {
    computed: {
        ...mapState({
            toastMsg: state => state.isToastShow.toastMsg,
            toastType: state => state.isToastShow.toastType
        }),
        getClass() {
            if (this.toastType == "success") {
                return "iconfont icon-toast_chenggong"
            } else if (this.toastType == "danger") {
                return "iconfont icon-toast-shibai_huaban"
            }
            return "iconfont icon-toast-jinggao"
        }

    },
}
/* 
  封装提示框组件的步骤:
   1. 样式结构
   2. 通过vuex中变量控制提示框显示隐藏
   3. 通过vuex中变量控制提示内容,提示图标
   4. 实现自动关闭功能 ( actions )
   5. 增加过渡效果 (transition)

*/
</script>
<style lang = "less" scoped>
.toast {
    position: fixed;
    padding: 20px 40px;
    display: flex;
    justify-content: center;
    align-items: center;
    background: #fff;
    left: 50%;
    top: 0;
    transform: translateX(-50%);
    border-radius: 10px;
    font-size: 30px;

    .iconfont {
        margin-right: 10px;
        font-size: 30px;
    }

    .icon-toast-shibai_huaban {
        color: red;
    }

    .icon-toast_chenggong {
        color: green;
    }

    .icon-toast-jinggao {
        color: orange;
    }
}

/* 入场的起始状态 = 离场的结束状态 */
.slide-enter,
.slide-leave-to {
    opacity: 0;
}

.slide-enter-active,
.slide-leave-active {
    transition: opacity .3s linear;
}

.slide-enter-to,
.slide-leave {
    opacity: 1;
}
</style>